package com.hangim.hangimsia.controller;
import java.util.Map;
import java.util.Date;

import com.hangim.hangimsia.model.SysVoice;
import com.hangim.hangimsia.service.SysVoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pig.common.constant.CommonConstant;
import com.baomidou.mybatisplus.plugins.Page;
import com.github.pig.common.util.Query;
import com.github.pig.common.util.R;
import com.github.pig.common.web.BaseController;

/**
 * <p>
 * 示范音标 前端控制器
 * </p>
 *
 * @author hongjiliang
 * @since 2018-10-20
 */
@RestController
@RequestMapping("/sysVoice")
public class SysVoiceController extends BaseController {
    @Autowired
    private SysVoiceService sysVoiceService;

    /**
    * 通过ID查询
    *
    * @param id ID
    * @return SysVoice
    */
    @GetMapping("/{id}")
    public R<SysVoice> get(@PathVariable Long id) {
        return new R<>(sysVoiceService.selectById(id));
    }


    /**
    * 分页查询信息
    *
    * @param params 分页对象
    * @return 分页对象
    */
    @RequestMapping("/page")
    public Page page(@RequestParam Map<String, Object> params) {
        params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL);
        return sysVoiceService.selectPage(new Query<>(params));
    }

    /**
     * 添加
     * @param  sysVoice  实体
     * @return success/false
     */
    @PostMapping
    public R<Integer> add(@RequestBody SysVoice sysVoice) {
        return new R<>(sysVoiceService.insert(sysVoice));
    }

    /**
     * 删除
     * @param id ID
     * @return success/false
     */
    @DeleteMapping("/{id}")
    public R<Integer> delete(@PathVariable Long id) {
        SysVoice sysVoice = new SysVoice();
        sysVoice.setId(id);
        sysVoice.setUpdatedAt(new Date());
        sysVoice.setActive(0);
        return new R<>(sysVoiceService.updateById(sysVoice));
    }

    /**
     * 编辑
     * @param  sysVoice  实体
     * @return success/false
     */
    @PutMapping
    public R<Integer> edit(@RequestBody SysVoice sysVoice) {
        sysVoice.setUpdatedAt(new Date());
        return new R<>(sysVoiceService.updateById(sysVoice));
    }
}
